﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gumini.JulaDB.DataTypes;

namespace Gumini.JulaDB.Expressions.Functions
{
    /// <summary>
    /// Returns absolute value of a number.
    /// </summary>
    internal class AbsFunction : ScalarFunction
    {
        public AbsFunction()
            : base("abs", 1) { }

        public override object Evaluate(IEnumerable<object> args)
        {
            decimal arg = (decimal)DataType.Number.ConvertFrom(args.Single());
            return Math.Abs(arg);
        }

        public override DataType GetReturnType()
        {
            return DataType.Number;
        }
    }
}
